//
// Created by 32827 on 2023/11/5.
//

#ifndef REYZ_YZ_I2C_LED1306_H
#define REYZ_YZ_I2C_LED1306_H
#include "yz.h"
#include "yz_i2c.h"
#include "yzl_conf.h"
#if YZLED1306

#define YZL_1306_I2C_TIMEOUT 1000

///此处位写地址0x3c << 1 ,0x3d << 1
#define YZL_1306_ADDRESS 0x3d
#define YZL_1306_ADDRESS2 0x3c

/**
 * 定义使用的led1306地址
 * */
#define YZL_1306_ADDRESS_USE YZL_1306_ADDRESS2

#define YZL_1306_OPEN 0xAF
#define YZL_1306_CLOSE 0xAE
#define YZL_1306_CONTENT_SCREEN 0xA4
#define YZL_1306_LIGHT_SCREEN 0xA5
#define YZL_1306_LIGHT_LEVEL_SCREEN 0x81

#define YZL_1306_LIGHT_BY_0 0xA7
#define YZL_1306_LIGHT_BY_1 0xA6

#define YZL_1306_RAM_SET_INC_MODE 0x20
#define YZL_1306_RAM_INC_MODE_HOR 0x00
#define YZL_1306_RAM_INC_MODE_VER 0x01
#define YZL_1306_RAM_INC_MODE_PAGE 0x02

#define YZL_1306_SET_LINE_START_END 0x21
#define YZL_1306_SET_PAGE_START_END 0x22

#define YZL_1306_DYNAMIC_SCREEN 0xA4
#define YZL_1306_STATIC_SCREEN 0xA5

#define YZL_1306_DIRECTION_LEFT_TO_RIGHT 0xa1
#define YZL_1306_DIRECTION_RIGHT_TO_LEFT 0xa0

#define YZL_1306_DIRECTION_TOP_TO_BOTTOM 0xc0
#define YZL_1306_DIRECTION_BOTTOM_TO_TOP 0xc8

#define YZL_1306_LED_LINES 0xA8
#define YZL_1306_LED_CLOCK 0xD5
#define YZL_1306_LED_CLOCK_MAX 0b11110000

#define YZL_1306_LED_Y_OFFSET 0xD3

#define YZL_1306_COMMAND 0b00000000
#define YZL_1306_DATA 0b01000000
#define YZL_1306_PAGE_BASE 0xB0
#define YZL_1306_COL_LOW_BASE 0x00
#define YZL_1306_COL_HIGH_BASE 0x10
#ifdef __cplusplus
extern "C" {
#endif

YZF_RESULT yzl_1306_open(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_close(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_light_screen(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_content_screen(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_light_level_screen(YZF_I2C_POINTER hi2c, uint8_t level);

YZF_RESULT yzl_1306_light_by_1(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_light_by_0(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_ram_inc_set(YZF_I2C_POINTER hi2c, uint8_t mode);

YZF_RESULT yzl_1306_ram_line_start_end_set(YZF_I2C_POINTER hi2c, uint8_t start, uint8_t end);

YZF_RESULT yzl_1306_ram_page_start_end_set(YZF_I2C_POINTER hi2c, uint8_t start, uint8_t end);

YZF_RESULT yzl_1306_col_low_set(YZF_I2C_POINTER hi2c, uint8_t col_low);

YZF_RESULT yzl_1306_col_high_set(YZF_I2C_POINTER hi2, uint8_t col_high);

YZF_RESULT yzl_1306_data_write(YZF_I2C_POINTER hi2c, uint8_t data);

YZF_RESULT yzl_1306_datas_write(YZF_I2C_POINTER hi2c, uint8_t *data, uint16_t len);

YZF_RESULT yzl_1306_page_set(YZF_I2C_POINTER hi2c, uint8_t page);

YZF_RESULT yzl_1306_lines_set(YZF_I2C_POINTER hi2c, uint8_t level);

YZF_RESULT yzl_1306_clock_set(YZF_I2C_POINTER hi2c, uint8_t reg_data);

YZF_RESULT yzl_1306_y_offset_set(YZF_I2C_POINTER hi2c, uint8_t offset);

///屏幕是否和内存同步
YZF_RESULT yzl_1306_dynamic_screen(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_static_screen(YZF_I2C_POINTER hi2c);

YZF_RESULT yzl_1306_direction_set(YZF_I2C_POINTER hi2c, uint8_t direction);


#if USE_SOFT_PORT

#include "yzl_softport_i2c.h"

YZF_RESULT yzl_1306_soft_open(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_close(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_light_screen(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_content_screen(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_light_level_screen(YZL_Soft_I2C *hi2c, uint8_t level);

YZF_RESULT yzl_1306_soft_light_by_1(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_light_by_0(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_ram_inc_set(YZL_Soft_I2C *hi2c, uint8_t mode);

YZF_RESULT yzl_1306_soft_ram_line_start_end_set(YZL_Soft_I2C *hi2c, uint8_t start, uint8_t end);

YZF_RESULT yzl_1306_soft_ram_page_start_end_set(YZL_Soft_I2C *hi2c, uint8_t start, uint8_t end);

YZF_RESULT yzl_1306_soft_col_low_set(YZL_Soft_I2C *hi2c, uint8_t col_low);

YZF_RESULT yzl_1306_soft_col_high_set(YZL_Soft_I2C *hi2, uint8_t col_high);

YZF_RESULT yzl_1306_soft_data_write(YZL_Soft_I2C *hi2c, uint8_t data);

YZF_RESULT yzl_1306_soft_datas_write(YZL_Soft_I2C *hi2c, uint8_t *data, uint16_t len);

YZF_RESULT yzl_1306_soft_page_set(YZL_Soft_I2C *hi2c, uint8_t page);

YZF_RESULT yzl_1306_soft_lines_set(YZL_Soft_I2C *hi2c, uint8_t level);

YZF_RESULT yzl_1306_soft_clock_set(YZL_Soft_I2C *hi2c, uint8_t reg_data);

YZF_RESULT yzl_1306_soft_y_offset_set(YZL_Soft_I2C *hi2c, uint8_t offset);

///屏幕是否和内存同步
YZF_RESULT yzl_1306_soft_dynamic_screen(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_static_screen(YZL_Soft_I2C *hi2c);

YZF_RESULT yzl_1306_soft_direction_set(YZL_Soft_I2C *hi2c, uint8_t direction);

#endif

#endif
#ifdef __cplusplus
}
#endif
#endif //REYZ_YZ_I2C_LED1306_H
